package com.sl.biz.modular.datasource.dao.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.datasource.dao.domain.dto.ProcessDataSourceDTO;
import com.sl.biz.modular.datasource.dao.domain.entity.ProcessDataSourceDO;
import com.sl.biz.modular.datasource.dao.mapper.ProcessDatasourceMapper;
import com.sl.biz.modular.datasource.dao.service.ProcessDatasourceDaoService;
import com.sl.common.enums.CommonDsiableFlagEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ProcessDatasourceDaoServiceImpl extends ServiceImpl<ProcessDatasourceMapper, ProcessDataSourceDO> implements ProcessDatasourceDaoService {
    @Override
    public List<ProcessDataSourceDTO> queryByList() {
        LambdaQueryWrapper<ProcessDataSourceDO> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(ProcessDataSourceDO::getGroupId, groupId);
        List<ProcessDataSourceDO> list = baseMapper.selectList(wrapper);
        return BeanUtil.copyToList(list, ProcessDataSourceDTO.class);
    }

    @Override
    public Boolean setStatusFlag(ProcessDataSourceDO assertUserUse) {
        LambdaUpdateChainWrapper<ProcessDataSourceDO> chainWrapper = new LambdaUpdateChainWrapper<>(baseMapper);
        chainWrapper.eq(ProcessDataSourceDO::getId, assertUserUse.getId());
        chainWrapper.set(ProcessDataSourceDO::getDisableFlag, assertUserUse.getDisableFlag());
        boolean ret = chainWrapper.update();
        return ret;
    }

    @Override
    public List<ProcessDataSourceDTO> queryEnableByList() {
        LambdaQueryWrapper<ProcessDataSourceDO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ProcessDataSourceDO::getDisableFlag, CommonDsiableFlagEnum.ENABLE_FLAG.getCode());
        List<ProcessDataSourceDO> list = baseMapper.selectList(wrapper);
        return BeanUtil.copyToList(list, ProcessDataSourceDTO.class);
    }
}
